package chapter01.part4;

import chapter01.part1.CountWordByLength;
import chapter01.part3.FilterMapFlatmap;

import java.util.List;
import java.util.stream.Stream;

/**
 * 抽取子流 & 组合流
 * 
 * @author insight 
 * @since 2021/7/19
 */
public class ExtractCombine {
    public static void main(String[] args) {
        List<String> words = CountWordByLength.getWordList();

        // 所以 generate 要配合 limit 使用
        Stream.generate(Math::random).limit(100);

        // 跳过元素
        words.stream().skip(1);

        // 条件为真时 获取/丢弃
        // 比如收集所有数字
        FilterMapFlatmap.codePoints("").takeWhile(s -> Character.isDigit(Integer.parseInt(s)));
        FilterMapFlatmap.codePoints("").dropWhile(s -> s.length() > 5);

        // 连接流
        // flatmap ?
        Stream.concat(FilterMapFlatmap.codePoints("Hello"),
                FilterMapFlatmap.codePoints("World"));
    }
}